package com.springboot.helloworld.controller;

import com.springboot.helloworld.bean.Result;

/**
 * @version v1.0
 * @description: 基础控制器
 * @author: xiaoliang.liu
 * @date: 2018/7/1 23:46
 */
public class BaseController {

    /**
     * 成功码
     */
    public static final int CODE_SUCCESS = 0;

    /**
     * 成功
     *
     * @param object 返回的对象
     * @return Result
     */
    public Result<Object> success(Object object) {
        Result<Object> result = new Result<>();
        result.setCode(CODE_SUCCESS);
        result.setDescription("成功");
        result.setData(object);
        return result;
    }

    /**
     * 成功
     *
     * @return Result
     */
    public Result<Object> success() {
        return success(null);
    }

    /**
     * 失败
     *
     * @param code        返回码
     * @param description 描述信息
     * @return Result
     */
    public Result<Object> fail(int code, String description) {
        Result<Object> result = new Result<>();
        result.setCode(code);
        result.setDescription(description);
        return result;
    }
}
